import {iProcessActionRender} from "react-cms-visual-editor/src/packages/createVisualEditorUser/createVisualEditorAction/createVisualEditorActionRender"
import {iVisualComponentActionData, RenderNode} from "react-cms-visual-editor/src/packages/utils/types.base"
import {Router} from "vue-router";

export const useActionRender = (router: Router) => {

    /**
     * 预定义动作渲染
     * @author  韦胜健
     * @date    2022/2/6 23:37
     */
    const processActionRender: iProcessActionRender = ({registryActionRender}) => {

        registryActionRender(
            '@@fixed',
            (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
                <a href={data.data} {...attrs}>
                    {content}
                </a>
            )
        )

        registryActionRender(
            'pdp',
            (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
                <nuxt-link to={`/pdp/${data.data.id}`} {...attrs}>
                    {content}
                </nuxt-link>
            ),)

        registryActionRender(
            'category',
            (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
                <nuxt-link to={`/plp?category=${data.data.id}`} {...attrs}>
                    {content}
                </nuxt-link>
            ),
        )

        /*registryActionRender(
            'activity',
            (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
                <a href={`activity?category=${data.data.code}`} {...attrs} onClick={(e) => {
                    openFail(e)
                    !!attrs.onClick && attrs.onClick(e)
                }}>
                    {content}
                </a>
            ),
        )*/
    }

    return processActionRender
}